// Copyright (c) 2014, the Dart project authors.  Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:test/test.dart';

import '../../descriptor.dart' as d;
import '../../test_pub.dart';

void main() {
  test('snapshots the executables for a Git repo', () async {
    ensureGit();

    await d.git('foo.git', [
      d.libPubspec('foo', '1.0.0'),
      d.dir('bin', [
        d.file('hello.dart', "void main() => print('hello!');"),
        d.file('goodbye.dart', "void main() => print('goodbye!');"),
        d.file('shell.sh', 'echo shell'),
        d.dir('subdir', [d.file('sub.dart', "void main() => print('sub!');")]),
      ]),
    ]).create();

    await runPub(
      args: ['global', 'activate', '-sgit', '../foo.git'],
      output: allOf([
        contains('Built foo:hello.'),
        contains('Built foo:goodbye.'),
      ]),
    );

    await d.dir(cachePath, [
      d.dir('global_packages', [
        d.dir('foo', [
          d.file('pubspec.lock', contains('1.0.0')),
          d.dir('bin', [
            d.file('hello.dart-$versionSuffix.snapshot', contains('hello!')),
            d.file(
              'goodbye.dart-$versionSuffix.snapshot',
              contains('goodbye!'),
            ),
            d.nothing('shell.sh-$versionSuffix.snapshot'),
            d.nothing('subdir'),
          ]),
        ]),
      ]),
    ]).validate();
  });
}
